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