home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / HookRun.pm < prev    next >
Encoding:
Perl POD Document  |  2004-09-23  |  13.4 KB  |  624 lines

  1. # /*
  2. #  * *********** WARNING **************
  3. #  * This file generated by ModPerl::WrapXS/0.01
  4. #  * Any changes made here will be lost
  5. #  * ***********************************
  6. #  * 01: lib/ModPerl/Code.pm:701
  7. #  * 02: O:\147xampp\sources\mod_perl-1.99_16\blib\lib/ModPerl/WrapXS.pm:584
  8. #  * 03: O:\147xampp\sources\mod_perl-1.99_16\blib\lib/ModPerl/WrapXS.pm:1100
  9. #  * 04: Makefile.PL:335
  10. #  * 05: Makefile.PL:283
  11. #  * 06: Makefile.PL:51
  12. #  */
  13.  
  14.  
  15. package Apache::HookRun;
  16.  
  17. use strict;
  18. use warnings FATAL => 'all';
  19.  
  20.  
  21.  
  22. use Apache::XSLoader ();
  23. our $VERSION = '0.01';
  24. Apache::XSLoader::load __PACKAGE__;
  25.  
  26.  
  27.  
  28. 1;
  29. __END__
  30.  
  31. =head1 NAME
  32.  
  33. Apache::HookRun - Perl API for Invoking Apache HTTP phases
  34.  
  35.  
  36.  
  37.  
  38. =head1 Synopsis
  39.  
  40.   # httpd.conf
  41.   PerlProcessConnectionHandler MyApache::PseudoHTTP::handler
  42.  
  43.   #file:MyApache/PseudoHTTP.pm
  44.   #---------------------------
  45.   package MyApache::PseudoHTTP;
  46.   
  47.   use Apache::HookRun ();
  48.   use Apache::RequestUtil ();
  49.   use Apache::RequestRec ();
  50.   
  51.   use Apache::Const -compile => qw(OK DECLINED DONE SERVER_ERROR);
  52.   
  53.   # implement the HTTP protocol cycle in protocol handler
  54.   sub handler {
  55.       my $c = shift;
  56.       my $r = Apache::RequestRec->new($c);
  57.   
  58.       # register any custom callbacks here, e.g.:
  59.       # $r->push_handlers(PerlAccessHandler => \&my_access);
  60.   
  61.       $rc = $r->run_post_read_request();
  62.       return $rc unless $rc == Apache::OK or $rc == Apache::DECLINED;
  63.   
  64.       $rc = $r->run_translate_name;
  65.       return $rc unless $rc == Apache::OK or $rc == Apache::DECLINED;
  66.   
  67.       $rc = $r->run_map_to_storage;
  68.       return $rc unless $rc == Apache::OK or $rc == Apache::DECLINED;
  69.   
  70.       # this must be run all a big havoc will happen in the following
  71.       # phases
  72.       $r->location_merge($path);
  73.   
  74.       $rc = $r->run_header_parser;
  75.       return $rc unless $rc == Apache::OK or $rc == Apache::DECLINED;
  76.   
  77.       my $args = $r->args || '';
  78.       if ($args eq 'die') {
  79.           $r->die(Apache::SERVER_ERROR);
  80.           return Apache::DONE;
  81.       }
  82.   
  83.       $rc = $r->run_access_checker;
  84.       return $rc unless $rc == Apache::OK or $rc == Apache::DECLINED;
  85.   
  86.       $rc = $r->run_auth_checker;
  87.       return $rc unless $rc == Apache::OK or $rc == Apache::DECLINED;
  88.   
  89.       $rc = $r->run_check_user_id;
  90.       return $rc unless $rc == Apache::OK or $rc == Apache::DECLINED;
  91.   
  92.       $rc = $r->run_type_checker;
  93.       return $rc unless $rc == Apache::OK or $rc == Apache::DECLINED;
  94.   
  95.       $rc = $r->run_fixups;
  96.       return $rc unless $rc == Apache::OK or $rc == Apache::DECLINED;
  97.   
  98.       # $r->run_handler is called internally by $r->invoke_handler,
  99.       # invoke_handler sets all kind of filters, and does a few other
  100.       # things but it's possible to call $r->run_handler, bypassing
  101.       # invoke_handler
  102.       $rc = $r->invoke_handler;
  103.       return $rc unless $rc == Apache::OK or $rc == Apache::DECLINED;
  104.   
  105.       $rc = $r->run_log_transaction;
  106.       return $rc unless $rc == Apache::OK or $rc == Apache::DECLINED;
  107.   
  108.       return Apache::OK;
  109.   }
  110.  
  111.  
  112.  
  113.  
  114.  
  115. =head1 Description
  116.  
  117. C<Apache::HookRun> exposes parts of the Apache HTTP protocol
  118. implementation, responsible for invoking callbacks for each L<HTTP
  119. Request cycle
  120. phase|docs::2.0::user::handlers::http/HTTP_Request_Cycle_Phases>.
  121.  
  122. Armed with that API, you could run some of the http protocol framework
  123. parts when implementing your own protocols. For example see how HTTP
  124. AAA (access, auth and authz) hooks are called from a protocol handler,
  125. implementing L<a command
  126. server|docs::2.0::user::handlers::protocols/Command_Server>, which has
  127. nothing to do with HTTP. Also you can see in L<Synopsis|/Synopsis> how
  128. to re-implement Apache HTTP cycle in the protocol handler.
  129.  
  130. Using this API you could probably also change the normal Apache
  131. behavior (e.g. invoking some hooks earlier than normal, or later), but
  132. before doing that you will probably need to spend some time reading
  133. through the Apache C code. That's why some of the methods in this
  134. document, point you to the specific functions in the Apache source
  135. code. If you just try to use the methods from this module, without
  136. understanding them well, don't be surprised if you will get some nasty
  137. crashes, from which mod_perl can't protect you.
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144. =head1 API
  145.  
  146. C<Apache::HookRun> provides the following functions and/or methods:
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155. =head2 C<die>
  156.  
  157. Kill the current request
  158.  
  159.   $r->die($type);
  160.  
  161. =over 4
  162.  
  163. =item obj: C<$r>
  164. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  165.  
  166. The current request
  167.  
  168. =item arg1: C<$type> ( integer )
  169.  
  170. Why the request is dieing. Expects an Apache status constant.
  171.  
  172. =item ret: no return value
  173.  
  174. =item since: 1.99_12
  175.  
  176. =back
  177.  
  178. This method doesn't really abort the request, it just handles the
  179. sending of the error response, logging the error and such.  You want
  180. to take a look at the internals of C<ap_die()> in
  181. F<httpd-2.0/modules/http/http_request.c> for more details.
  182.  
  183.  
  184.  
  185.  
  186.  
  187. =head2 C<invoke_handler>
  188.  
  189. Run the
  190. L<response|docs::2.0::user::handlers::http/PerlResponseHandler> phase.
  191.  
  192.   $rc = $r->invoke_handler();
  193.  
  194. =over 4
  195.  
  196. =item obj: C<$r>
  197. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  198.  
  199. The current request
  200.  
  201. =item ret: C<$rc> ( integer )
  202.  
  203. The status of the current phase run: C<Apache::OK>,
  204. C<Apache::HTTP_...>
  205.  
  206. =item since: 1.99_12
  207.  
  208. =back
  209.  
  210. C<invoke_handler()> allows modules to insert filters, sets a default
  211. handler if none is set, runs C<L<run_handler()|/C_run_handler_>> and
  212. handles some errors.
  213.  
  214. For more details see C<ap_invoke_handler()> in
  215. F<httpd-2.0/server/config.c>.
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224. =head2 C<run_access_checker>
  225.  
  226. Run the resource L<access
  227. control|docs::2.0::user::handlers::http/PerlAccessHandler> phase.
  228.  
  229.   $rc = $r->run_access_checker();
  230.  
  231. =over 4
  232.  
  233. =item obj: C<$r>
  234. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  235.  
  236. the current request
  237.  
  238. =item ret: C<$rc> ( integer )
  239.  
  240. The status of the current phase run: C<Apache::OK>,
  241. C<Apache::DECLINED>, C<Apache::HTTP_...>.
  242.  
  243. =item since: 1.99_12
  244.  
  245. =back
  246.  
  247. This phase runs before a user is authenticated, so this hook is really
  248. to apply additional restrictions independent of a user. It also runs
  249. independent of 'C<Require>' directive usage.
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257. =head2 C<run_auth_checker>
  258.  
  259. Run the
  260. L<authentication|docs::2.0::user::handlers::http/PerlAuthenHandler>
  261. phase.
  262.  
  263.   $rc = $r->run_auth_checker();
  264.  
  265. =over 4
  266.  
  267. =item obj: C<$r>
  268. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  269.  
  270. the current request
  271.  
  272. =item ret: C<$rc> ( integer )
  273.  
  274. The status of the current phase run: C<Apache::OK>,
  275. C<Apache::DECLINED>, C<Apache::HTTP_...>.
  276.  
  277. =item since: 1.99_12
  278.  
  279. =back
  280.  
  281. This phase is used to check to see if the resource being requested is
  282. available for the authenticated user (C<$r-E<gt>user> and
  283. C<$r-E<gt>ap_auth_type>).
  284.  
  285. It runs after the L<access_checker|/C_run_access_checker_> and
  286. L<check_user_id|/C_run_auth_checker_> hooks.
  287.  
  288. Note that it will only be called if Apache determines that access
  289. control has been applied to this resource (through a 'C<Require>'
  290. directive).
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298. =head2 C<run_check_user_id>
  299.  
  300. Run the
  301. L<authorization|docs::2.0::user::handlers::http/PerlAuthzHandler>
  302. phase.
  303.  
  304.   $rc = $r->run_check_user_id();
  305.  
  306. =over 4
  307.  
  308. =item obj: C<$r>
  309. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  310.  
  311. The current request
  312.  
  313. =item ret: C<$rc> ( integer )
  314.  
  315. The status of the current phase run: C<Apache::OK>,
  316. C<Apache::DECLINED>, C<Apache::HTTP_...>.
  317.  
  318. =item since: 1.99_12
  319.  
  320. =back
  321.  
  322. This hook is used to analyze the request headers, authenticate the
  323. user, and set the user information in the request record
  324. (C<$r-E<gt>user> and C<$r-E<gt>ap_auth_type>).
  325.  
  326. This hook is only run when Apache determines that
  327. authentication/authorization is required for this resource (as
  328. determined by the 'C<Require>' directive).
  329.  
  330. It runs after the L<access_checker|/C_run_access_checker_> hook, and
  331. before the L<auth_checker|/C_run_auth_checker_> hook.
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340. =head2 C<run_fixups>
  341.  
  342. Run the L<fixup|docs::2.0::user::handlers::http/PerlFixupHandler>
  343. phase.
  344.  
  345.   $rc = $r->run_fixups();
  346.  
  347. =over 4
  348.  
  349. =item obj: C<$r>
  350. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  351.  
  352. The current request
  353.  
  354. =item ret: C<$rc> ( integer )
  355.  
  356. The status of the current phase run: C<Apache::OK>,
  357. C<Apache::DECLINED>, C<Apache::HTTP_...>.
  358.  
  359. =item since: 1.99_12
  360.  
  361. =back
  362.  
  363. This phase allows modules to perform module-specific fixing of HTTP
  364. header fields.  This is invoked just before the
  365. L<response|docs::2.0::user::handlers::http/PerlResponseHandler> phase.
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372. =head2 C<run_handler>
  373.  
  374. Run the
  375. L<response|docs::2.0::user::handlers::http/PerlResponseHandler> phase.
  376.  
  377.   $rc = $r->run_handler();
  378.  
  379. =over 4
  380.  
  381. =item obj: C<$r>
  382. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  383.  
  384. The request_rec
  385.  
  386. =item ret: C<$rc> ( integer )
  387.  
  388. The status of the current phase run: C<Apache::OK>,
  389. C<Apache::DECLINED>, C<Apache::HTTP_...>.
  390.  
  391. =item since: 1.99_12
  392.  
  393. =back
  394.  
  395. C<run_handler()> is called internally by
  396. C<L<invoke_handler()|/C_invoke_handler_>>. Use C<run_handler()> only
  397. if you want to bypass the extra functionality provided by
  398. C<L<invoke_handler()|/C_invoke_handler_>>.
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407. =head2 C<run_header_parser>
  408.  
  409. Run the L<header
  410. parser|docs::2.0::user::handlers::http/PerlHeaderParserHandler> phase.
  411.  
  412.   $rc = $r->run_header_parser();
  413.  
  414. =over 4
  415.  
  416. =item obj: C<$r>
  417. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  418.  
  419. The current request
  420.  
  421. =item ret: C<$rc> ( integer )
  422.  
  423. C<Apache::OK> or C<Apache::DECLINED>.
  424.  
  425. =item since: 1.99_12
  426.  
  427. =back
  428.  
  429.  
  430.  
  431.  
  432.  
  433. =head2 C<run_log_transaction>
  434.  
  435. Run the L<logging|docs::2.0::user::handlers::http/PerlLogHandler>
  436. phase.
  437.  
  438.   $rc = $r->run_log_transaction();
  439.  
  440. =over 4
  441.  
  442. =item obj: C<$r>
  443. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  444.  
  445. The current request
  446.  
  447. =item ret: C<$rc> ( integer )
  448.  
  449. The status of the current phase run: C<Apache::OK>,
  450. C<Apache::DECLINED>, C<Apache::HTTP_...>
  451.  
  452. =item since: 1.99_12
  453.  
  454. =back
  455.  
  456. This hook allows modules to perform any module-specific logging
  457. activities over and above the normal server things.
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464. =head2 C<run_map_to_storage>
  465.  
  466. Run the
  467. L<map_to_storage|docs::2.0::user::handlers::http/PerlMapToStorageHandler>
  468. phase.
  469.  
  470.   $rc = $r->run_map_to_storage();
  471.  
  472. =over 4
  473.  
  474. =item obj: C<$r>
  475. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  476.  
  477. The current request
  478.  
  479. =item ret: C<$rc> ( integer )
  480.  
  481. C<Apache::DONE> (or C<Apache::HTTP_*>) if this contextless request was
  482. just fulfilled (such as C<TRACE>), C<Apache::OK> if this is not a
  483. file, and C<Apache::DECLINED> if this is a file.  The core
  484. map_to_storage (C<Apache::HOOK_RUN_LAST>) will C<directory_walk()> and
  485. C<file_walk()> the C<$r-E<gt>filename> (all internal C functions).
  486.  
  487. =item since: 1.99_12
  488.  
  489. =back
  490.  
  491. This phase allows modules to set the per_dir_config based on their own
  492. context (such as C<E<lt>ProxyE<gt>> sections) and responds to
  493. contextless requests such as C<TRACE> that need no security or
  494. filesystem mapping based on the filesystem.
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501. =head2 C<run_post_read_request>
  502.  
  503.  
  504. Run the
  505. L<post_read_request|docs::2.0::user::handlers::http/PerlPostReadRequestHandler>
  506. phase.
  507.  
  508.   $rc = $r->run_post_read_request();
  509.  
  510. =over 4
  511.  
  512. =item obj: C<$r>
  513. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  514.  
  515. The current request
  516.  
  517. =item ret: C<$rc> ( integer )
  518.  
  519. The status of the current phase run: C<Apache::OK> or
  520. C<Apache::DECLINED>.
  521.  
  522. =item since: 1.99_12
  523.  
  524. =back
  525.  
  526. This phase is run right after C<read_request()> or
  527. C<internal_redirect()>, and not run during any subrequests.  This hook
  528. allows modules to affect the request immediately after the request has
  529. been read, and before any other phases have been processes.  This
  530. allows modules to make decisions based upon the input header fields
  531.  
  532.  
  533.  
  534.  
  535.  
  536. =head2 C<run_translate_name>
  537.  
  538. Run the L<translate|docs::2.0::user::handlers::http/PerlTransHandler>
  539. phase.
  540.  
  541.   $rc = $r->run_translate_name();
  542.  
  543. =over 4
  544.  
  545. =item obj: C<$r>
  546. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  547.  
  548. The current request
  549.  
  550. =item ret: C<$rc> ( integer )
  551.  
  552. The status of the current phase run: C<Apache::OK>,
  553. C<Apache::DECLINED>, C<Apache::HTTP_...>.
  554.  
  555. =item since: 1.99_12
  556.  
  557. =back
  558.  
  559. This phase gives modules an opportunity to translate the URI into an
  560. actual filename.  If no modules do anything special, the server's
  561. default rules will be applied.
  562.  
  563.  
  564.  
  565.  
  566.  
  567. =head2 C<run_type_checker>
  568.  
  569. Run the
  570. L<type_checker|docs::2.0::user::handlers::http/PerlTypeHandler> phase.
  571.  
  572.   $rc = $r->run_type_checker();
  573.  
  574. =over 4
  575.  
  576. =item obj: C<$r>
  577. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  578.  
  579. the current request
  580.  
  581. =item ret: C<$rc> ( integer )
  582.  
  583. The status of the current phase run: C<Apache::OK>,
  584. C<Apache::DECLINED>, C<Apache::HTTP_...>.
  585.  
  586. =item since: 1.99_12
  587.  
  588. =back
  589.  
  590. This phase is used to determine and/or set the various document type
  591. information bits, like C<Content-type> (via C<$r-E<gt>content_type>),
  592. language, etc.
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600. =head1 See Also
  601.  
  602. L<mod_perl 2.0 documentation|docs::2.0::index>.
  603.  
  604.  
  605.  
  606.  
  607. =head1 Copyright
  608.  
  609. mod_perl 2.0 and its core modules are copyrighted under
  610. The Apache Software License, Version 2.0.
  611.  
  612.  
  613.  
  614.  
  615. =head1 Authors
  616.  
  617. L<The mod_perl development team and numerous
  618. contributors|about::contributors::people>.
  619.  
  620. =cut
  621.  
  622.