home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Online / Apache / bin / apxs < prev    next >
Text File  |  1999-11-11  |  19KB  |  627 lines

  1. #!/bin/perl
  2. ## ====================================================================
  3. ## Copyright (c) 1998-1999 The Apache Group.  All rights reserved.
  4. ##
  5. ## Redistribution and use in source and binary forms, with or without
  6. ## modification, are permitted provided that the following conditions
  7. ## are met:
  8. ##
  9. ## 1. Redistributions of source code must retain the above copyright
  10. ##    notice, this list of conditions and the following disclaimer. 
  11. ##
  12. ## 2. Redistributions in binary form must reproduce the above copyright
  13. ##    notice, this list of conditions and the following disclaimer in
  14. ##    the documentation and/or other materials provided with the
  15. ##    distribution.
  16. ##
  17. ## 3. All advertising materials mentioning features or use of this
  18. ##    software must display the following acknowledgment:
  19. ##    "This product includes software developed by the Apache Group
  20. ##    for use in the Apache HTTP server project (http://www.apache.org/)."
  21. ##
  22. ## 4. The names "Apache Server" and "Apache Group" must not be used to
  23. ##    endorse or promote products derived from this software without
  24. ##    prior written permission. For written permission, please contact
  25. ##    apache@apache.org.
  26. ##
  27. ## 5. Products derived from this software may not be called "Apache"
  28. ##    nor may "Apache" appear in their names without prior written
  29. ##    permission of the Apache Group.
  30. ##
  31. ## 6. Redistributions of any form whatsoever must retain the following
  32. ##    acknowledgment:
  33. ##    "This product includes software developed by the Apache Group
  34. ##    for use in the Apache HTTP server project (http://www.apache.org/)."
  35. ##
  36. ## THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  37. ## EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  39. ## PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  40. ## ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  42. ## NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  43. ## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  44. ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  45. ## STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  46. ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  47. ## OF THE POSSIBILITY OF SUCH DAMAGE.
  48. ## ====================================================================
  49. ##
  50. ## This software consists of voluntary contributions made by many
  51. ## individuals on behalf of the Apache Group and was originally based
  52. ## on public domain software written at the National Center for
  53. ## Supercomputing Applications, University of Illinois, Urbana-Champaign.
  54. ## For more information on the Apache Group and the Apache HTTP server
  55. ## project, please see <http://www.apache.org/>.
  56. ##
  57.  
  58. ##
  59. ##  apxs -- APache eXtenSion tool
  60. ##  Written by Ralf S. Engelschall <rse@apache.org>
  61. ##
  62.  
  63. require 5.003;
  64. use strict;
  65. package apxs;
  66.  
  67. ##
  68. ##  Configuration
  69. ##
  70.  
  71. my $CFG_TARGET        = 'httpd';        # substituted via Makefile.tmpl 
  72. my $CFG_CC            = 'gcc';            # substituted via Makefile.tmpl
  73. my $CFG_CFLAGS        = '-m68020-40 -O2 -resident32 -mstackextend -Dfork=vfork `../apaci`';        # substituted via Makefile.tmpl
  74. my $CFG_CFLAGS_SHLIB  = '';  # substituted via Makefile.tmpl
  75. my $CFG_LD_SHLIB      = '';      # substituted via Makefile.tmpl
  76. my $CFG_LDFLAGS_SHLIB = ''; # substituted via Makefile.tmpl 
  77. my $CFG_LIBS_SHLIB    = '';    # substituted via Makefile.tmpl 
  78. my $CFG_PREFIX        = '/usr/local/apache';        # substituted via APACI install
  79. my $CFG_SBINDIR       = '/usr/local/apache/bin';       # substituted via APACI install
  80. my $CFG_INCLUDEDIR    = '/usr/local/apache/include';    # substituted via APACI install
  81. my $CFG_LIBEXECDIR    = '/usr/local/apache/libexec';    # substituted via APACI install
  82. my $CFG_SYSCONFDIR    = '/usr/local/apache/conf';    # substituted via APACI install
  83.  
  84. ##
  85. ##  Cleanup the above stuff
  86. ##
  87. $CFG_CFLAGS =~ s|^\s+||;
  88. $CFG_CFLAGS =~ s|\s+$||;
  89. $CFG_CFLAGS =~ s|\s+`.+apaci`||;
  90.  
  91. ##
  92. ##  Initial shared object support check
  93. ##
  94. if (not -x "$CFG_SBINDIR/$CFG_TARGET") {
  95.     print STDERR "apxs:Error: $CFG_SBINDIR/$CFG_TARGET not found or not executable\n";
  96.     exit(1);
  97. }
  98. if (not grep(/mod_so/, `$CFG_SBINDIR/$CFG_TARGET -l`)) {
  99.     print STDERR "apxs:Error: Sorry, no shared object support for Apache\n";
  100.     print STDERR "apxs:Error: available under your platform. Make sure\n";
  101.     print STDERR "apxs:Error: the Apache module mod_so is compiled into\n";
  102.     print STDERR "apxs:Error: your server binary `$CFG_SBINDIR/$CFG_TARGET'.\n";
  103.     exit(1);
  104. }
  105.  
  106. ##
  107. ##  parse argument line
  108. ##
  109.  
  110. #   defaults for parameters
  111. my $opt_n = '';
  112. my $opt_g = '';
  113. my $opt_c = 0;
  114. my $opt_o = '';
  115. my @opt_D = ();
  116. my @opt_I = ();
  117. my @opt_L = ();
  118. my @opt_l = ();
  119. my @opt_W = ();
  120. my $opt_i = 0;
  121. my $opt_a = 0;
  122. my $opt_A = 0;
  123. my $opt_q = 0;
  124.  
  125. #   this subroutine is derived from Perl's getopts.pl with the enhancement of
  126. #   the "+" metacharater at the format string to allow a list to be build by
  127. #   subsequent occurance of the same option.
  128. sub Getopts {
  129.     my ($argumentative, @ARGV) = @_;
  130.     my (@args, $first, $rest, $pos);
  131.     my ($errs) = 0;
  132.     local ($_);
  133.     local ($[) = 0;
  134.  
  135.     @args = split( / */, $argumentative);
  136.     while(@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
  137.         ($first, $rest) = ($1,$2);
  138.         if ($_ =~ m|^--$|) {
  139.             shift(@ARGV);
  140.             last;
  141.         }
  142.         $pos = index($argumentative,$first);
  143.         if($pos >= $[) {
  144.             if($args[$pos+1] eq ':') {
  145.                 shift(@ARGV);
  146.                 if($rest eq '') {
  147.                     unless (@ARGV) {
  148.                         print STDERR "apxs:Error: Incomplete option: $first (needs an argument)\n";
  149.                         ++$errs;
  150.                     }
  151.                     $rest = shift(@ARGV);
  152.                 }
  153.                 eval "\$opt_$first = \$rest;";
  154.             }
  155.             elsif ($args[$pos+1] eq '+') {
  156.                 shift(@ARGV);
  157.                 if($rest eq '') {
  158.                     unless (@ARGV) {
  159.                         print STDERR "apxs:Error: Incomplete option: $first (needs an argument)\n";
  160.                         ++$errs;
  161.                     }
  162.                     $rest = shift(@ARGV);
  163.                 }
  164.                 eval "push(\@opt_$first, \$rest);";
  165.             }
  166.             else {
  167.                 eval "\$opt_$first = 1";
  168.                 if($rest eq '') {
  169.                     shift(@ARGV);
  170.                 }
  171.                 else {
  172.                     $ARGV[0] = "-$rest";
  173.                 }
  174.             }
  175.         }
  176.         else {
  177.             print STDERR "apxs:Error: Unknown option: $first\n";
  178.             ++$errs;
  179.             if($rest ne '') {
  180.                 $ARGV[0] = "-$rest";
  181.             }
  182.             else {
  183.                 shift(@ARGV);
  184.             }
  185.         }
  186.     }
  187.     return ($errs == 0, @ARGV);
  188. }
  189.  
  190. sub usage {
  191.     print STDERR "Usage: apxs -g -n <modname>\n";
  192.     print STDERR "       apxs -q <query> ...\n";
  193.     print STDERR "       apxs -c [-o <dsofile>] [-D <name>[=<value>]] [-I <incdir>]\n";
  194.     print STDERR "               [-L <libdir>] [-l <libname>] [-Wc,<flags>] [-Wl,<flags>]\n";
  195.     print STDERR "               <files> ...\n";
  196.     print STDERR "       apxs -i [-a] [-A] [-n <modname>] <dsofile> ...\n";
  197.     exit(1);
  198. }
  199.  
  200. #   option handling
  201. my $rc;
  202. ($rc, @ARGV) = &Getopts("qn:gco:I+D+L+l+W+iaA", @ARGV);
  203. &usage if ($rc == 0);
  204. &usage if ($#ARGV == -1 and not $opt_g);
  205. &usage if (not $opt_q and not ($opt_g and $opt_n) and not $opt_i and not $opt_c);
  206.  
  207. #   argument handling
  208. my @args = @ARGV;
  209. my $name = 'unknown';
  210. $name = $opt_n if ($opt_n ne '');
  211.  
  212. ##
  213. ##  Operation
  214. ##
  215.  
  216. #   helper function for executing a list of
  217. #   system command with return code checks
  218. sub execute_cmds {
  219.     my (@cmds) = @_;
  220.     my ($cmd, $rc);
  221.  
  222.     foreach $cmd (@cmds) {
  223.         print STDERR "$cmd\n";
  224.         $rc = system("$cmd");
  225.         if ($rc != 0) {
  226.             printf(STDERR "apxs:Break: Command failed with rc=%d\n", $rc << 8);
  227.             exit(1);
  228.         }
  229.     }
  230. }
  231.  
  232. if ($opt_g) {
  233.     ##
  234.     ##  SAMPLE MODULE SOURCE GENERATION
  235.     ##
  236.  
  237.     if (-d $name) {
  238.         print STDERR "apxs:Error: Directory `$name' already exists. Remove first\n";
  239.         exit(1);
  240.     }
  241.  
  242.     my $data = join('', <DATA>);
  243.     $data =~ s|%NAME%|$name|sg;
  244.     $data =~ s|%TARGET%|$CFG_TARGET|sg;
  245.  
  246.     my ($mkf, $src) = ($data =~ m|^(.+)-=#=-\n(.+)|s);
  247.  
  248.     print STDERR "Creating [DIR]  $name\n";
  249.     system("mkdir $name");
  250.     print STDERR "Creating [FILE] $name/Makefile\n";
  251.     open(FP, ">${name}/Makefile") || die;
  252.     print FP $mkf;
  253.     close(FP);
  254.     print STDERR "Creating [FILE] $name/mod_$name.c\n";
  255.     open(FP, ">${name}/mod_${name}.c") || die;
  256.     print FP $src;
  257.     close(FP);
  258.  
  259.     exit(0);
  260. }
  261.  
  262.  
  263. if ($opt_q) {
  264.     ##
  265.     ##  QUERY INFORMATION 
  266.     ##
  267.  
  268.     my $result = '';
  269.     my $arg;
  270.     foreach $arg (@args) {
  271.         my $ok = 0;
  272.         my $name;
  273.         foreach $name (qw(
  274.             TARGET CC CFLAGS CFLAGS_SHLIB LD_SHLIB LDFLAGS_SHLIB LIBS_SHLIB
  275.             PREFIX SBINDIR INCLUDEDIR LIBEXECDIR SYSCONFDIR
  276.         )) {
  277.             if ($arg eq $name or $arg eq lc($name)) {
  278.                 my $val = eval "\$CFG_$name";
  279.                 $result .= "${val}::";
  280.                 $ok = 1;
  281.             }
  282.         }
  283.         if (not $ok) {
  284.             printf(STDERR "apxs:Error: Invalid query string `%s'\n", $arg);
  285.             exit(1);
  286.         }
  287.     }
  288.     $result =~ s|::$||;
  289.     $result =~ s|::| |;
  290.     print $result;
  291. }
  292.  
  293. if ($opt_c) {
  294.     ##
  295.     ##  SHARED OBJECT COMPILATION
  296.     ##
  297.  
  298.     #   split files into sources and objects
  299.     my @srcs = ();
  300.     my @objs = ();
  301.     my $f;
  302.     foreach $f (@args) {
  303.         if ($f =~ m|\.c$|) {
  304.             push(@srcs, $f);
  305.         }
  306.         else {
  307.             push(@objs, $f);
  308.         }
  309.     }
  310.  
  311.     #   determine output file
  312.     my $dso_file;
  313.     if ($opt_o eq '') {
  314.         if ($#srcs > -1) {
  315.             $dso_file = $srcs[0];
  316.             $dso_file =~ s|\.[^.]+$|.so|;
  317.         }
  318.         elsif ($#objs > -1) {
  319.             $dso_file = $objs[0];
  320.             $dso_file =~ s|\.[^.]+$|.so|;
  321.         }
  322.         else {
  323.             $dso_file = "mod_unknown.so";
  324.         }
  325.     }
  326.     else {
  327.         $dso_file = $opt_o;
  328.     }
  329.  
  330.     #   create compilation commands
  331.     my @cmds = ();
  332.     my $opt = '';
  333.     my ($opt_Wc, $opt_I, $opt_D);
  334.     foreach $opt_Wc (@opt_W) {
  335.         $opt .= "$1 " if ($opt_Wc =~ m|^\s*c,(.*)$|);
  336.     }
  337.     foreach $opt_I (@opt_I) {
  338.         $opt .= "-I$opt_I ";
  339.     }
  340.     foreach $opt_D (@opt_D) {
  341.         $opt .= "-D$opt_D ";
  342.     }
  343.     my $cflags = "$CFG_CFLAGS $CFG_CFLAGS_SHLIB";
  344.     my $s;
  345.     foreach $s (@srcs) {
  346.         my $o = $s;
  347.         $o =~ s|\.c$|.o|;
  348.         push(@cmds, "$CFG_CC $cflags -I$CFG_INCLUDEDIR $opt -c $s");
  349.         unshift(@objs, $o);
  350.     }
  351.  
  352.     #   create link command
  353.     my $cmd = "$CFG_LD_SHLIB $CFG_LDFLAGS_SHLIB -o $dso_file";
  354.     my $o;
  355.     foreach $o (@objs) {
  356.         $cmd .= " $o";
  357.     }
  358.     $opt = '';
  359.     my ($opt_Wl, $opt_L, $opt_l);
  360.     foreach $opt_Wl (@opt_W) {
  361.         $opt .= " $1" if ($opt_Wl =~ m|^\s*l,(.*)$|);
  362.     }
  363.     foreach $opt_L (@opt_L) {
  364.         $opt .= " -L$opt_L";
  365.     }
  366.     foreach $opt_l (@opt_l) {
  367.         $opt .= " -l$opt_l";
  368.     }
  369.     $cmd .= $opt;
  370.     $cmd .= " $CFG_LIBS_SHLIB";
  371.     push(@cmds, $cmd);
  372.  
  373.     #   execute the commands
  374.     &execute_cmds(@cmds);
  375.  
  376.     #   allow one-step compilation and installation
  377.     if ($opt_i) {
  378.         @args = ( $dso_file );
  379.     }
  380. }
  381.  
  382. if ($opt_i) {
  383.     ##
  384.     ##  SHARED OBJECT INSTALLATION
  385.     ##
  386.  
  387.     #   determine installation commands
  388.     #   and corresponding LoadModule/AddModule directives
  389.     my @lmd = ();
  390.     my @amd = ();
  391.     my @cmds = ();
  392.     my $f;
  393.     foreach $f (@args) {
  394.         if ($f !~ m|\.so$|) {
  395.             print STDERR "apxs:Error: file $f is not a shared object\n";
  396.             exit(1);
  397.         }
  398.         my $t = $f;
  399.         $t =~ s|^.+/([^/]+)$|$1|;
  400.         push(@cmds, "cp $f $CFG_LIBEXECDIR/$t");
  401.         push(@cmds, "chmod 755 $CFG_LIBEXECDIR/$t");
  402.  
  403.         #   determine module symbolname and filename
  404.         my $filename = '';
  405.         if ($name eq 'unknown') {
  406.             $name = '';
  407.             my $base = $f;
  408.             $base =~ s|\.[^.]+$||;
  409.             if (-f "$base.c") {
  410.                 open(FP, "<$base.c");
  411.                 my $content = join('', <FP>);
  412.                 close(FP);
  413.                 if ($content =~ m|.*module\s+(?:MODULE_VAR_EXPORT\s+)?([a-zA-Z0-9_]+)_module\s*=\s*.*|s) {
  414.                     $name = "$1";
  415.                     $filename = "$base.c";
  416.                     $filename =~ s|^[^/]+/||;
  417.                 }
  418.             }
  419.             if ($name eq '') {
  420.                 if ($base =~ m|.*mod_([a-zA-Z0-9_]+)\..+|) {
  421.                     $name = "$1";
  422.                     $filename = $base;
  423.                     $filename =~ s|^[^/]+/||;
  424.                 }
  425.             }
  426.             if ($name eq '') {
  427.                 print "apxs:Error: Sorry, cannot determine bootstrap symbol name\n";
  428.                 print "apxs:Error: Please specify one with option `-n'\n";
  429.                 exit(1);
  430.             }
  431.         }
  432.         if ($filename eq '') {
  433.             $filename = "mod_${name}.c";
  434.         }
  435.         my $dir = $CFG_LIBEXECDIR;
  436.         $dir =~ s|^$CFG_PREFIX/?||;
  437.         $dir =~ s|(.)$|$1/|;
  438.         push(@lmd, sprintf("LoadModule %-18s %s", "${name}_module", "$dir$t"));
  439.         push(@amd, sprintf("AddModule %s", $filename));
  440.     }
  441.  
  442.     #   execute the commands
  443.     &execute_cmds(@cmds);
  444.  
  445.     #   activate module via LoadModule/AddModule directive
  446.     if ($opt_a or $opt_A) {
  447.         if (not -f "$CFG_SYSCONFDIR/$CFG_TARGET.conf") {
  448.             print "apxs:Error: Config file $CFG_SYSCONFDIR/$CFG_TARGET.conf not found\n";
  449.             exit(1);
  450.         }
  451.  
  452.         open(FP, "<$CFG_SYSCONFDIR/$CFG_TARGET.conf") || die;
  453.         my $content = join('', <FP>);
  454.         close(FP);
  455.  
  456.         if ($content !~ m|\n#?\s*LoadModule\s+|) {
  457.             print STDERR "apxs:Error: Activation failed for custom $CFG_SYSCONFDIR/$CFG_TARGET.conf file.\n";
  458.             print STDERR "apxs:Error: At least one `LoadModule' directive already has to exist.\n";
  459.             exit(1);
  460.         }
  461.  
  462.         my $update = 0;
  463.         my $lmd;
  464.         foreach $lmd (@lmd) {
  465.             if ($content !~ m|\n#?\s*$lmd|) {
  466.                  my $c = '';
  467.                  $c = '#' if ($opt_A);
  468.                  $content =~ s|^(.*\n#?\s*LoadModule\s+[^\n]+\n)|$1$c$lmd\n|sg;
  469.                  $update = 1;
  470.                  $lmd =~ m|LoadModule\s+(.+?)_module.*|;
  471.                  my $what = $opt_A ? "preparing" : "activating";
  472.                  print STDERR "[$what module `$1' in $CFG_SYSCONFDIR/$CFG_TARGET.conf]\n";
  473.             }
  474.         }
  475.         my $amd;
  476.         foreach $amd (@amd) {
  477.             if ($content !~ m|\n#?\s*$amd|) {
  478.                  my $c = '';
  479.                  $c = '#' if ($opt_A);
  480.                  $content =~ s|^(.*\n#?\s*AddModule\s+[^\n]+\n)|$1$c$amd\n|sg;
  481.                  $update = 1;
  482.             }
  483.         }
  484.         if ($update) {
  485.             open(FP, ">$CFG_SYSCONFDIR/$CFG_TARGET.conf.new") || die;
  486.             print FP $content;
  487.             close(FP);
  488.             system("cp $CFG_SYSCONFDIR/$CFG_TARGET.conf $CFG_SYSCONFDIR/$CFG_TARGET.conf.bak && " .
  489.                    "cp $CFG_SYSCONFDIR/$CFG_TARGET.conf.new $CFG_SYSCONFDIR/$CFG_TARGET.conf && " .
  490.                    "rm $CFG_SYSCONFDIR/$CFG_TARGET.conf.new");
  491.         }
  492.     }
  493. }
  494.  
  495. ##EOF##
  496. __DATA__
  497. ##
  498. ##  Makefile -- Build procedure for sample %NAME% Apache module
  499. ##  Autogenerated via ``apxs -n %NAME% -g''.
  500. ##
  501.  
  502. #   the used tools
  503. APXS=apxs
  504. APACHECTL=apachectl
  505.  
  506. #   additional defines, includes and libraries
  507. #DEF=-Dmy_define=my_value
  508. #INC=-Imy/include/dir
  509. #LIB=-Lmy/lib/dir -lmylib
  510.  
  511. #   the default target
  512. all: mod_%NAME%.so
  513.  
  514. #   compile the shared object file
  515. mod_%NAME%.so: mod_%NAME%.c
  516.     $(APXS) -c $(DEF) $(INC) $(LIB) mod_%NAME%.c
  517.  
  518. #   install the shared object file into Apache 
  519. install: all
  520.     $(APXS) -i -a -n '%NAME%' mod_%NAME%.so
  521.  
  522. #   cleanup
  523. clean:
  524.     -rm -f mod_%NAME%.o mod_%NAME%.so
  525.  
  526. #   simple test
  527. test: reload
  528.     lynx -mime_header http://localhost/%NAME%
  529.  
  530. #   install and activate shared object by reloading Apache to
  531. #   force a reload of the shared object file
  532. reload: install restart
  533.  
  534. #   the general Apache start/restart/stop
  535. #   procedures
  536. start:
  537.     $(APACHECTL) start
  538. restart:
  539.     $(APACHECTL) restart
  540. stop:
  541.     $(APACHECTL) stop
  542.  
  543. -=#=-
  544. /* 
  545. **  mod_%NAME%.c -- Apache sample %NAME% module
  546. **  [Autogenerated via ``apxs -n %NAME% -g'']
  547. **
  548. **  To play with this sample module first compile it into a
  549. **  DSO file and install it into Apache's libexec directory 
  550. **  by running:
  551. **
  552. **    $ apxs -c -i mod_%NAME%.c
  553. **
  554. **  Then activate it in Apache's %TARGET%.conf file for instance
  555. **  for the URL /%NAME% in as follows:
  556. **
  557. **    #   %TARGET%.conf
  558. **    LoadModule %NAME%_module libexec/mod_%NAME%.so
  559. **    <Location /%NAME%>
  560. **    SetHandler %NAME%
  561. **    </Location>
  562. **
  563. **  Then after restarting Apache via
  564. **
  565. **    $ apachectl restart
  566. **
  567. **  you immediately can request the URL /%NAME and watch for the
  568. **  output of this module. This can be achieved for instance via:
  569. **
  570. **    $ lynx -mime_header http://localhost/%NAME% 
  571. **
  572. **  The output should be similar to the following one:
  573. **
  574. **    HTTP/1.1 200 OK
  575. **    Date: Tue, 31 Mar 1998 14:42:22 GMT
  576. **    Server: Apache/1.3.4 (Unix)
  577. **    Connection: close
  578. **    Content-Type: text/html
  579. **  
  580. **    The sample page from mod_%NAME%.c
  581. */ 
  582.  
  583. #include "httpd.h"
  584. #include "http_config.h"
  585. #include "http_protocol.h"
  586. #include "ap_config.h"
  587.  
  588. /* The sample content handler */
  589. static int %NAME%_handler(request_rec *r)
  590. {
  591.     r->content_type = "text/html";      
  592.     ap_send_http_header(r);
  593.     if (!r->header_only)
  594.         ap_rputs("The sample page from mod_%NAME%.c\n", r);
  595.     return OK;
  596. }
  597.  
  598. /* Dispatch list of content handlers */
  599. static const handler_rec %NAME%_handlers[] = { 
  600.     { "%NAME%", %NAME%_handler }, 
  601.     { NULL, NULL }
  602. };
  603.  
  604. /* Dispatch list for API hooks */
  605. module MODULE_VAR_EXPORT %NAME%_module = {
  606.     STANDARD_MODULE_STUFF, 
  607.     NULL,                  /* module initializer                  */
  608.     NULL,                  /* create per-dir    config structures */
  609.     NULL,                  /* merge  per-dir    config structures */
  610.     NULL,                  /* create per-server config structures */
  611.     NULL,                  /* merge  per-server config structures */
  612.     NULL,                  /* table of config file commands       */
  613.     %NAME%_handlers,       /* [#8] MIME-typed-dispatched handlers */
  614.     NULL,                  /* [#1] URI to filename translation    */
  615.     NULL,                  /* [#4] validate user id from request  */
  616.     NULL,                  /* [#5] check if the user is ok _here_ */
  617.     NULL,                  /* [#3] check access by host address   */
  618.     NULL,                  /* [#6] determine MIME type            */
  619.     NULL,                  /* [#7] pre-run fixups                 */
  620.     NULL,                  /* [#9] log a transaction              */
  621.     NULL,                  /* [#2] header parser                  */
  622.     NULL,                  /* child_init                          */
  623.     NULL,                  /* child_exit                          */
  624.     NULL                   /* [#0] post read-request              */
  625. };
  626.  
  627.